<template>
   <el-container>
    <el-header>Header</el-header>
    <el-container>
      <el-aside class="aside-main">
        <el-menu default-active="1" 
          class="el-menu-content"  
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse">
          <CpMenu :menuData="menuData"></CpMenu>
        </el-menu>
        <div class="collepse-menu" @click="collepseMenuHandle">{{collepseMenuTitle}}</div>
      </el-aside>
      <el-main class="layout-main">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts">
import {ref, onMounted, reactive, defineAsyncComponent} from 'vue'
import $ from "jquery";

export default {
  name: 'App',
  // 必须包裹defineAsyncComponent
  components: {
    CpMenu: defineAsyncComponent(() => import('./components/Menu.vue'))
  },
  setup() {
    const scale = ref<number>(1);
    const collepseMenuTitle = ref<string>('收起')
    const isCollapse = ref<boolean>(false)
    const menuData = reactive([{
      title: '首页',
      icon: 'el-icon-menu',
      path: '/home',
      id: '1',
      children: []
    }])
    onMounted(()=> {
      $(window).resize(function () {
        
        console.log('自适应', document.documentElement.clientWidth)
        scale.value =  document.documentElement.clientWidth/1920

        console.log(scale.value)
      });
    });
    const collepseMenuHandle = () => {
      isCollapse.value = !isCollapse.value;
      if(isCollapse.value){
        collepseMenuTitle.value ='展开'
      } else {
        collepseMenuTitle.value ='收起'
      }
    }
    return {
      scale,
      menuData,
      collepseMenuTitle,
      isCollapse,
      collepseMenuHandle
    }
  }
}
</script>
<style lang="less" scoped>

.layout-main{
  transform: scale(v-bind(scale));
  padding: 0
}
.aside-main{
  background: #545c64;
  max-width: 200px;
  position: relative;
  width: auto;
  .collepse-menu{
    position: absolute;
    top: 50%;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    text-align: center;
    line-height: 50px;
    color: #ffffff;
    background: #000;
    right: 20px;
    z-index: 100;
    cursor: pointer;
  }
}
.el-menu-content{
  border: none
}
.el-menu-content:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
  overflow: hidden;
  
}
.el-menu--collapse .el-submenu__title span{ display: none; }
.el-menu--collapse .el-submenu__title .el-submenu__icon-arrow{ display: none; }
</style>

